package sctu.edu.java.year2016.team07.project.client;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * Created by Huang Suixin on 2016/6/25.
 */
public class ClientFrame extends JFrame {
    public ClientFrame(String title) {
        setTitle( "您好！" + title);
        setBounds(150, 150, 700, 500);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);        //设置窗口不可改变
        setAlwaysOnTop(true);       //设置窗口总在最前面
        setBackground(Color.WHITE);

        //设置窗口背景
        try {
            ImageIcon background = new ImageIcon(ImageIO.read((new File("src\\main\\java\\sctu\\edu\\java\\year2016\\team07\\project\\image\\land_background.jpg"))));
            JLabel label = new JLabel(background);
            label.setBounds(0, 0, background.getIconWidth(), background.getIconHeight());
            JPanel imagePanel = (JPanel) this.getContentPane();     //将内容窗格式转化成JPanel，否则不能使用方法setOpaque()来使内容窗格透明
            imagePanel.setOpaque(false);         //使用方法setOpaque()来是内容窗格透明
            imagePanel.setLayout(new FlowLayout());
            getLayeredPane().setLayout(null);

            getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
